import { BFFormItem, BFTabsForm } from '@/components/bf-form-parse/src/bf-form.parse'
import { BFTableColumn } from '@/components/bf-table/src/bf-table'
import { reactive, ref } from 'vue'
export type CurdOptions<T = any> = {
  r?: (page: number, size: number) => Promise<{ list: any[]; total: number }>
  c?: (newData: T) => Promise<{ success: boolean; msg: string }>
  u?: (newData: T) => Promise<{ success: boolean; msg: string }>
  d?: (keys: string[]) => Promise<{ success: boolean; msg: string }>
}

export type TableState<T = any> = {
  columns?: BFTableColumn[]
  tableData?: T[]
  selectKeys?: string[]
}

export type FormState<T = any> = {
  formData?: T
  template?: Array<BFFormItem & BFTabsForm>
}

export const useModal = () => {
  const modalVisible = ref(false)
  return { modalVisible }
}

export const useTable = <T = any>(
  options: TableState<T> = { columns: [], tableData: [], selectKeys: [] }
) => {
  const tableState = reactive({ ...options })
  return tableState
}

export const useForm = <T = any>(options: FormState<T> = { template: [], formData: {} as T }) => {
  const formState = reactive({ ...options })
  return formState
}

export const useCurd = <T = any>(options: CurdOptions<T> = {}) => {
  return { ...options }
}
